﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace myWallet.App_Code
{
    public class LanguageHelper
    {
        public static void SetLanguage()
        {
            try
            {
                HttpContext.Current.Session["lang"] = ((System.Web.Configuration.GlobalizationSection)(System.Configuration.ConfigurationManager.GetSection("system.web/globalization"))).UICulture;
                HttpContext.Current.Response.Cookies["lang"].Value = ((System.Web.Configuration.GlobalizationSection)(System.Configuration.ConfigurationManager.GetSection("system.web/globalization"))).UICulture;
                HttpContext.Current.Response.Cookies["lang"].Expires = DateTime.Now.AddDays(30);
            }
            catch (Exception)
            {
                HttpContext.Current.Session["lang"] = "vi-VN";
                HttpContext.Current.Response.Cookies["lang"].Value = "vi-VN";
                HttpContext.Current.Response.Cookies["lang"].Expires = DateTime.Now.AddDays(30);
            }
        }

        public static void SetLanguage(string lang)
        {
            try
            {
                HttpContext.Current.Session["lang"] = lang;
                HttpContext.Current.Response.Cookies["lang"].Value = lang;
                HttpContext.Current.Response.Cookies["lang"].Expires = DateTime.Now.AddDays(30);
            }
            catch (Exception)
            {
                SetLanguage();
            }
        }
    }
}